package com.example.gdeserver.contr;

import com.example.gdeserver.bean.DataEntity;
import com.example.gdeserver.mapper.DataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class Data {
    @Autowired
    DataMapper dataMapper;

    //    公司列表
    @GetMapping("/company")
    public List<DataEntity> getCompany() {
        return dataMapper.getCompanys();
    }

    //    公司下面的程序
    @GetMapping("/companysoftusage/{compname}")
    public List<Map<String, Object>> getCompanySoftUsage(@PathVariable("compname") String compname) {
        return dataMapper.getProgramUsageNumberByCompany(compname);
    }

    //    程序使用的地理位置
    @GetMapping("/getSoftwareUsagePlace/{softwarename}")
    public List<Map<String, Object>> getSoftwareUsagePlace(@PathVariable("softwarename") String softwarename) {
        return dataMapper.getSoftwareUsagePlace(softwarename);
    }

    //    使用者性别
    @GetMapping("/softwareUsageInfo/{processname}")
    public ArrayList<List<Map<String, Object>>> getSoftwareUsageGender(@PathVariable("processname") String processname) {
        ArrayList<List<Map<String, Object>>> lists = new ArrayList<>();
        lists.add(dataMapper.getSoftwareUsageCity(processname));
        lists.add(dataMapper.getSoftwareUsageGender(processname));
        lists.add(dataMapper.getSoftwareUsageBirthday(processname));
        lists.add(dataMapper.getSoftwareUsageEdu(processname));
        lists.add(dataMapper.getSoftwareUsageJob(processname));
        lists.add(dataMapper.getSoftwareUsageIncome(processname));
        return lists;
    }


    // 软件使用排行，网站排行
    @GetMapping("/index")
    public ArrayList<List<Map<String, Object>>> index(  ) {
        ArrayList<List<Map<String, Object>>> lists = new ArrayList<>();
        lists.add(dataMapper.allSoftwareUsage());
        lists.add(dataMapper.allWebsitsUsage());
        return lists;
    }

    @GetMapping("/sql/{sql}")
    public  List<Map<String, Object>>   sql(@PathVariable("sql") String sqlstatement){
        System.out.println(sqlstatement);
        return dataMapper.sql(sqlstatement) ;
    }

}
